package com.tgu.utils.result;

/**
 * 系统返回枚举
 */
public enum SystemCodeEnum implements ResultCode {

    //系统响应成功
    SYSTEM_OK(0, "success"),
    //未捕获的错误
    SYSTEM_ERROR(500, "网络错误"),
    //拒绝访问
    SYSTEM_BAD_REQUEST(403, "请求频率过快,请稍后再试"),
    //无权访问
    SYSTEM_NO_AUTH(401, "无权操作"),
    //资源未找到
    SYSTEM_NO_FOUND(404, "资源未找到"),
    //资源未找到
    SYSTEM_NO_VALID(400, "参数验证错误"),
    //请求方式错误
    SYSTEM_METHOD_ERROR(405, "请求方式错误"),
    //请求超时
    SYSTEM_REQUEST_TIMEOUT(408, "请求超时"),
    //服务调用异常
    SYSTEM_SERVER_ERROR(10001, "服务调用异常"),
    //TOKEN 过期或 TOKEN 不存在
    TOKEN_EXPIRE(10002, "无效token"),
    OPERATION_LOG_ERROR(10003,"操作日志记录失败"),
    IPUTILS_ERROR(10004,"获取ip地址失败"),
    // 业务成功
    POST_SUCCESS(20001, "发布成功"),
    LOGIN_SUCCESS(20002, "登录成功"),
    REGISTER_SUCCESS(20003, "注册成功"),
    SELECT_SUCCESS(20004, "查询成功"),
    TAKE_ORDER_SUCCESS(20005, "抢单成功"),
    FINISH_SUCCESS(20006, "完成订单"),
    USER_CANCEL_SUCCESS(20007, "用户取消订单成功"),
    RIDER_CANCEL_SUCCESS(20008, "骑手取消订单成功"),
    INSERT_TROLLEY_SUCCESS(20009, "加入购物车成功"),
    TROLLEY_DELETE_SUCCESS(20010, "删除成功"),
    PAY_SUCCESS(20011, "支付成功"),
    RECHARGE_SUCCESS(20012, "充值成功"),
    COMMENT_SUCCESS(20013, "评论成功"),
    USER_INFO_CHANGE_SUCCESS(20014, "用户信息修改成功"),
    APPROVE_ACCEPT_SUCCESS(20015, "通过认证处理成功"),
    APPROVE_REFUSE_SUCCESS(20016, "拒绝认证处理成功"),
    APPROVE_CALLBACK_SUCCESS(20017, "认证驳回处理成功"),
    APPROVE_SUBMIT_SUCCESS(20018, "认证信息提交成功"),
    // 业务失败
    PHONE_NUMBER_ERROR(30001, "手机号有误"),
    MONEY_NUMBER_ERROR(30002, "金额有误"),
    POST_ERROR(30003, "发布失败"),
    USER_NOT_EXIST(30004, "用户不存在"),
    PASSWORD_ERROR(30005, "密码错误"),
    REGISTER_ERROR(30006, "注册失败"),
    USER_TYPE_ERROR(30007, "用户类型错误"),
    ORDER_NOT_EXIST(30008, "订单不存在"),
    USER_CANCEL_ERROR(30009, "用户取消订单失败"),
    RIDER_CANCEL_ERROR(30010, "骑手取消订单失败"),
    USER_EXISTED(30011, "用户已存在"),
    INSERT_TROLLEY_ERROR(30012, "加入购物车失败"),
    LOGIN_TIME_OUT(30013, "登录过期"),
    MONEY_NOT_ENOUGH(30014, "余额不足"),
    RECHARGE_ERROR(30015, "充值失败"),
    DATA_ERROR(30016, "数据错误"),
    INSERT_COMMENT_ERROR(30017, "评论失败"),
    USER_INFO_CHANGE_ERROR(30018, "用户信息修改失败"),
    APPROVE_ACCEPT_ERROR(30019, "通过认证处理失败"),
    APPROVE_REFUSE_ERROR(30019, "拒绝认证处理失败"),
    APPROVE_NOT_EXIST(30020, "认证信息不存在"),
    APPROVE_CALLBACK_ERROR(30021, "认证驳回处理失败"),
    APPROVE_SUBMIT_ERROR(30022, "认证信息提交失败"),
    ;

    SystemCodeEnum(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    private int code;
    private String msg;

    @Override
    public int getCode() {
        return code;
    }

    @Override
    public String getMsg() {
        return msg;
    }

    public static SystemCodeEnum parse(Integer status) {
        for (SystemCodeEnum value : values()) {
            if (value.getCode() == status) {
                return value;
            }
        }
        return SystemCodeEnum.SYSTEM_ERROR;
    }

}
